import React from "react";
import style from "./index.module.scss";

import header from "../../base/Header/index";

import MapGD from "../../component/MapGD";

import {Toast} from "antd-mobile";
const loadingToast = ()=> {
    Toast.loading('Loading...', 3, () => {
        // console.log('Load complete !!!');
    });
}
const offline = ()=> {
    Toast.offline('Network connection failed !!!', 2);
}

import {getBookOnSellList} from "../../serverAPI/index";

class NearbyOnsell extends React.Component{
    constructor(props){
        super(props);
        this.props = props;
        this.state={
            nearbyOnSellList:[]
        }
    }

    static defaultProps={
        booklist:[
            {
                name:"边城",
                cover:require("../../common/image/book-cover-default.png").default,
                position:{ 
                    longitude: 115.406,
                    latitude: 38.910
                }
            },
           {
                bid:"123123",
                name:"沉默的大多数",
                cover:require("../../common/image/1.png").default,
                position:{
                    address:"123123",
                    longitude: 116.406,
                    latitude: 39.910
                }
           },
        ]
    }

    getBookOnSellList(){
        getBookOnSellList("nearby",{},res=>{
            let {code,data,msg}=res;
            if(code == "01") this.setState({nearbyOnSellList:data});
            else {
                console.log(msg)
                offline();
            }
        })
    }

    componentDidMount(){
        loadingToast();
        setTimeout(()=>{
            this.getBookOnSellList();
        },1000);
    }

    render(){
        
        return (
            <div className={style["index-root"]}>
                {header({title:"附近在售", history:this.props.history})}

                <div className={style["map-box"]}>
                    <MapGD history={this.props.history} bookList={this.state.nearbyOnSellList} />
                </div>
            </div>
        )
    }
}

export default NearbyOnsell;